package org.dormi.learn.primitive;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;

/**
 * 币种
 *
 * @author : dormi330
 * @version : 1.0
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Currency {

    RMB("RMB", "¥"),
    USD("USD", "$"),
    GBP("GBP", "€"),
    POINT("POINT", "#"), // 积分
    ;

    /** 在特定命名空间时, 唯一编码 */
    private final String code;

    /** 货币符号, 如 $ */
    private final String note;

    Currency(String code, String note) {
        this.code = code;
        this.note = note;
    }

    @JsonCreator
    public static Currency findValue(@JsonProperty("code") String code) {
        if (null == code) return null;

        return Arrays.stream(Currency.values())
                .filter(pt -> pt.code.equals(code))
                .findFirst()
                .orElse(null);
    }

    /* === set/get === */
    /* === set/get === */
    /* === set/get === */

    public String getCode() {
        return code;
    }

    public String getNote() {
        return note;
    }

}
